package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(81)
public class LianxianGameStrategy extends BaseGameStrategy {

    public static final String URL = "http://113.46.230.156:30288/gmsss/user/gmquery.php";
    public static final String CLEAR = "http://113.46.230.156:30288/gmsss/user/clearBag.php";
    public static final String SHENQI = "http://113.46.230.156:30288/gmsss/user/shenqi.php";

    /**
     * type=charge&checknum=diyao88&uid=m66666&chargetype=0_101&num=1&qu=1
     * @param item
     * @return
     */
    @GongnengMethod(8101)
    public String pay(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("checknum", "diyao88");
        params.add("type", "charge");
        params.add("qu", "1");

        params.add("uid", item.uid);
        params.add("num", item.number);
        params.add("chargetype", item.itemId);

        RestTemplateUtil.sendPostForm(URL, params);
        return "发送成功,直接到账";
    }

    /**
     * type=mail&checknum=diyao88&uid=m66666&item=1_30010&num=20&qu=1
     * @param item
     * @return
     */
    @GongnengMethod(8102)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("checknum", "diyao88");
        params.add("type", "mail");
        params.add("qu", "1");

        params.add("uid", item.uid);
        params.add("num", item.number);
        params.add("item", item.itemId);

        RestTemplateUtil.sendPostForm(URL, params);
        return "发送成功,邮件到账";
    }



    @GongnengMethod(8103)
    public String clear(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("uid", item.uid);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(CLEAR, params,"info");
    }


    /**
     * 更新数据库，修改神器升级材料：气运精华和注灵精元
     * @param item
     * @return
     */
    @GongnengMethod(8104)
    public String shenqicailiao(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("uid", item.uid);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(SHENQI, params,"info");
    }

    public static void main(String[] args) {
        SendItem item = new SendItem();
        item.uid = "m66666";
        item.number = "2";
        item.itemId = "0_101";
        System.out.println(new LianxianGameStrategy().shenqicailiao(item));
    }
}

